package site.hackway.bean;

import my.mvc.IUser;
import my.mvc.RequestContext;
import org.apache.commons.lang.StringUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by hackway on 2016/5/16.
 */
public class User implements IUser {

    public static User GetLoginUser(HttpServletRequest req) {
        User loginUser = (User)req.getAttribute(G_USER);
        if (loginUser == null) {
            IUser cookie_user = RequestContext.get().getUserFromCookie();
            if(cookie_user == null) return null;
            /*User user = User.Read(cookie_user.getId());
            if(user != null && StringUtils.equalsIgnoreCase(user.getPwd(), cookie_user.getPwd()) && !user.IsBlocked()) {
                user.PostLogin(req);
                return user;
            }*/
        }
        return loginUser;
    }

    /**
     * 用户编号
     *
     * @return
     */
    @Override
    public long getId() {
        return 0;
    }

    /**
     * 用户密码
     *
     * @return
     */
    @Override
    public String getPwd() {
        return null;
    }

    /**
     * 返回用户角色
     *
     * @return
     */
    @Override
    public int getRole() {
        return 0;
    }

    /**
     * 判断是否具备某个用户角色
     *
     * @param role
     * @return
     */
    @Override
    public boolean IsRoleOf(int role) {
        return false;
    }

    /**
     * 判断用户是否被阻止使用
     *
     * @return
     */
    @Override
    public boolean IsBlocked() {
        return false;
    }
}
